package concurrent.tool;

import java.util.Date;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CallableFureTest4 {

	public static void main(String[] args) throws ExecutionException, InterruptedException {
		
		System.out.println("开始。。。");
		
		//在其他线程执行耗时任务
		FutureTask<Void> future = new FutureTask<>(new CallVoid()); //FutureTask实现Runable和Future
		new Thread(future).start();
		
		Thread.sleep(3000); //代表要做一些其他的操作
		System.out.println("主线程执行完毕");
		
		System.out.println(future.get());
	}
}

class CallVoid implements Callable<Void>{

	@Override
	public Void call() throws Exception {
		
		if(System.currentTimeMillis() < new Date().getTime()+1){
			
//			throw new OutOfMemoryError("内存溢出");
		}
		
		Thread.sleep(5000);
		System.out.println(Thread.currentThread().getName() + "执行完毕");
		return null;
	}
}
